package com.aurora.oa.work.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.GridView;
import android.widget.TextView;

import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.R;
import com.aurora.oa.activity.BaseActivity;
import com.aurora.oa.application.MyApplication;
import com.aurora.oa.listener.OnRequestExpenceDetailListener;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.utils.DateUtil;
import com.aurora.oa.utils.ToastUtil;
import com.aurora.oa.work.adapter.ImageSeeAdapter;
import com.aurora.oa.work.bean.AttachmentBean;
import com.aurora.oa.work.bean.ExpenceBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/21 0021.
 */
public class ExpenceDetailActivity extends BaseActivity {

    String id;
    RequestHttpModel model = new RequestHttpModelImpl();
    @Bind(R.id.sdv_head_img)
    SimpleDraweeView sdvHeadImg;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.tv_expence_type)
    TextView tvExpenceType;
    @Bind(R.id.tv_expence_money)
    TextView tvExpenceMoney;
    @Bind(R.id.tv_who_sell)
    TextView tvWhoSell;
    @Bind(R.id.tv_remark)
    TextView tvRemark;
    @Bind(R.id.tv_approve)
    TextView tvApprove;
    @Bind(R.id.gv_work_images)
    GridView gvWorkImages;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitlebar(true, "报销详情", true);
        setMyContentView(R.layout.activity_expence_detail);
        ButterKnife.bind(this);
        getData();
    }

    private void getData() {
        id = getIntent().getStringExtra("id");
        model.getExpenceDetail(id, new OnRequestExpenceDetailListener() {
            @Override
            public void onRequestExpenceDetailSuccess(ExpenceBean expenceBean) {
                initView(expenceBean);
            }

            @Override
            public void onRequestExpenceDetailFail(String message) {
                ToastUtil.show(getApplicationContext(), message);
            }
        });
    }

    private void initView(ExpenceBean expenceBean) {
        sdvHeadImg.setImageURI(AuroraConstants.BASE_SERVER_URL + "/" + expenceBean.userHeadImage);
        tvName.setText(expenceBean.username);
        tvTime.setText(DateUtil.getDateTime(expenceBean.createtime));
        tvExpenceType.setText(expenceBean.expensetype);
        tvExpenceMoney.setText(expenceBean.money+"");
        tvWhoSell.setText(expenceBean.seller);
        tvRemark.setText(expenceBean.remark);
        String approvalstate = "";
        switch (expenceBean.approvalstate) {
            case 1:
                approvalstate = "未审核";
                break;
            case 2:
                approvalstate = "审核通过）";
                break;
            case 3:
                approvalstate = "审核不通过）";
                break;
        }
        tvApprove.setText(approvalstate);
        //把图片地址取出来用
        List<String> uriList = new ArrayList<>();
        if (null != expenceBean.attachments) {
            for (AttachmentBean e : expenceBean.attachments) {
                uriList.add(AuroraConstants.BASE_SERVER_URL + "/" + e.path);
            }
        }
        gvWorkImages.setAdapter(new ImageSeeAdapter(getApplicationContext(), uriList));

    }
}
